<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Customer</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>邮件管理</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="javascript:;" lay-filter="table-search">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">类型:</label>
                            <div class="layui-input-inline">
                                <select name="type" class="layui-select">
                                    <option value="">--请选择--</option>
                                    <option value="0" selected>手动发送</option>
                                    <option value="1">活动返利</option>
                                    <option value="2">日常奖励</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="send"><i class="layui-icon"></i> 手动发送(后台自定义参数)</button>

                                <button type="button" class="layui-btn" id="roleIdText" title="大批量角色ID.txt">
                                    <i class="layui-icon layui-icon-upload"></i> 大批量角色ID导入
                                </button>

                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add" auth="package:add">新增</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<style>
    .layui-table-cell { /*自适应行高*/
        height: auto !important;
        white-space: normal;
    }
</style>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script type="text/html" id="packageContent">

    {{#if (d.item) { }}
    <div>
        {{# layui.each(d.item,function(key,val){ }}
        <p>{{val.itemId}}({{val.itemName}}):{{ val.number}}{{val.isBind==1?':绑定':''}}</p>
        {{# }) }}
    </div>
    {{# } }}

    {{#if (d.coin) { }}
    <div>
        {{# layui.each(d.coin, function(key, val) { }}
        <p>
            {{ val.coinType == 10 ? '金币' : '' }}
            {{ val.coinType == 11 ? '金券' : '' }}
            {{ val.coinType == 20 ? '银币' : '' }}
            {{ val.coinType == 21 ? '铜币' : '' }}
            {{ val.coinType == 30 ? '公会资金' : '' }}
            {{ val.coinType == 31 ? '公会活跃度' : '' }}
            {{ val.coinType == 32 ? '公会贡献' : '' }}
            {{ val.coinType == 40 ? '角色经验' : '' }}
            {{ val.coinType == 41 ? '活跃度' : '' }}
            {{ val.coinType == 42 ? 'PK值' : '' }}
            {{ val.coinType == 50 ? '功勋' : '' }}
            * {{ val.number }}
        </p>
        {{# }) }}
    </div>
    {{# } }}
</script>
<script type="text/html" id="btns">
    {{# if(d.auth_status==0){ }}
    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="auth" auth="package:auth">
        通过审核
    </button>
    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="noauth" auth="package:noauth">
        拒绝审核
    </button>
    {{# } }}
</script>

<script>
    layui.use(['form', 'table','upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            upload = layui.upload;


          table.render({
            width:2000,
            where: form.val('table-search'),
            elem: '#currentTableId',
            url: '/admin/package/paginate',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'print' ],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 80, title: 'ID', sort: true},
                {field: 'title',width:150, title: '邮件标题'},
                {field: 'content', width:260,title: '邮件描述'},
                {field:"game_areas",title: '区服编码'},
                {field:"receiver",title: '接收者',width:220},
                {title: '礼包内容',width:230,templet:'#packageContent'},
                {field: 'count_down', title: '倒计时发送'},
                {field: 'create_time', title: '创建时间',width:220,templet:function(row){
                    return getYMDHMS(row.create_time)
                    }},
                {field: 'send_status', title: '发送状态',templet: function (row) {
                         var v = row.send_status;
                        if (v == -1) return "发送失败";
                        if (v == 0) return "待发送";
                        if (v == 1) return "发送成功";
                    }},
                {field: 'auth_status', title: '审核状态',templet: function (row) {
                        var v = row.auth_status;
                        if (v==0) return '待审核';
                        if (v==1) return '已通过';
                        if (v==-1) return '已拒绝';
                    }},
                {field:'auth_time',title:"审核时间",width:220,templet: function(row){
                        if (row.auth_time){
                            return getYMDHMS(row.auth_time)
                        }
                        return '未审核';
                    }},
                {field:'操作',width:500,templet: '#btns'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line',
        });

        upload.render({
            elem: '#roleIdText',
            exts:"txt",
            accept: 'file', // 只接受文件
            url:"/admin/package/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('*/',{icon:1})
                }
            }
        });

         var tableReload = function(){
             //执行搜索重载
             table.reload('currentTableId');
         }
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'add.html',
                });

            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: form.val('table-search')
            }, 'data');
            return false;
        });

        // 监听搜索操作
        form.on('submit(send)', function () {
            layer.confirm('您确定通过吗?',{title:"提示"},function(){
                $.post("/admin/package/sendText/",function(res){
                    if (res.code!=0){
                        layer.msg(res.msg,{icon:5})
                    }else {
                        layer.msg(res.msg,{icon:1})
                    }
                    tableReload()
                })
            })
            return false;
        });


        table.on('tool(currentTableFilter)', function (obj) {
            var row = obj.data;
            if(obj.event==='auth'){
                layer.confirm('您确定通过吗?',{title:"提示"},function(){
                    $.post("/admin/package/auth/"+obj.data.id,{_method:"put"},function(res){
                        if (res.code!=0){
                            layer.msg(res.msg,{icon:5})
                        }else {
                            layer.msg(res.msg,{icon:1})
                        }
                        tableReload()
                    })
                })
            } else if(obj.event==='noauth'){
                layer.confirm('您确定拒绝吗?',{title:"提示"},function(){
                    $.post("/admin/package/noauth/"+obj.data.id,{_method:"put"},function(res){
                        if (res.code!=0){
                            layer.msg(res.msg,{icon:5})
                        }else {
                            layer.msg(res.msg,{icon:1})
                        }
                        tableReload()
                    })
                })
            }
        });
    });
</script>
</body>
</html>